package com.sweet.mealon.face.daily.lock.clh;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @author: crazier.huang
 * @project: faceDaily
 * @date: 2021/4/29 星期四
 * @desc:
 */
@AllArgsConstructor
@Data
public class Student {

    private int i = 0;
    private CLHLock clhLock;

    public Student(CLHLock clhLock) {
        this.clhLock = clhLock;
    }

    public void add(){
        clhLock.lock();
        this.i = this.i+1;
        System.out.println(String.format("线程%s的变量i=%s", Thread.currentThread().getName(), this.i));
        clhLock.unlock();
    }
}
